<template>
  <div>
    <div v-if="fixed" class="suspend-wrapper">
      <div class="suspend-placeholder" />
      <div class="suspend-fixed">
        <el-button v-if="cancelBtn" :size="size" @click="handleClose">{{ cancelBtnText }}</el-button>
        <el-button :loading="loading" type="primary" :disabled="loading" :size="size" @click="handelConfirm" v-text="confirmBtnText" />
      </div>
    </div>

    <el-row v-else type="flex" :justify="justify">
      <el-button v-if="cancelBtn" :size="size" @click="handleClose">{{ cancelBtnText }}</el-button>
      <el-button :loading="loading" type="primary" :disabled="loading" :size="size" @click="handelConfirm">
        {{ confirmBtnText }}
      </el-button>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'FormFooter',
  props: {
    fixed: {
      type: Boolean,
      default: false
    },
    // 提交中
    loading: {
      type: Boolean,
      default: false
    },
    cancelBtn: {
      type: Boolean,
      default: true
    },
    justify: {
      type: String,
      default: 'center'
    },
    size: {
      type: String,
      default: 'small'
    },
    cancelBtnText: {
      type: String,
      default: '取消'
    },
    confirmBtnText: {
      type: String,
      default: '确认'
    }
  },
  methods: {
    handleClose() {
      this.$emit('cancel');
    },
    handelConfirm() {
      this.$emit('submit')
    }
  }
}
</script>

<style lang="scss" scoped>
.suspend-wrapper {
  .suspend-placeholder {
    height: 80px;
  }
  .suspend-fixed {
    height: 55px;
    position: fixed;
    left: 231px;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    border-top: 1px solid #e4e7ed;
    .el-button--medium {
      padding: 10px 30px;
    }
  }
}
</style>
